﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace igflow
{
    class RectMesh : NodeBoxMesh
    {
        public RectMesh(float w, float h, float thickness, string texture)
        {
            //cornerW = w / 4;
            cornerW = thickness;
            if (w < (cornerW * 3))
            {
                w = cornerW * 3;
            }
            if (h < (cornerW * 3))
            {
                h = cornerW * 3;
            }
            float newW = w - (2 * cornerW);
            float newh = w - (2 * cornerW);

            //Textures = new List<Texture2D>();
            //Textures.Add(World.contentManager.Load<Texture2D>(texture));
            vertexDeclaration = new VertexDeclaration(World.Graphics.GraphicsDevice, VertexPositionColorTexture.VertexElements);

            Vertices = new VertexPositionColorTexture[4 * 16];
            Indexes = new short[6 * 16];

            Vector3 TL = new Vector3(-w / 2, h / 2, 0.0f);
            CreateQuad(TL, cornerW, cornerW, new Vector2(0, 0), new Vector2(0.25f, 0.25f));
            TL += new Vector3(cornerW, 0, 0);
            CreateQuad(TL, newW, cornerW, new Vector2(0.25f, 0), new Vector2(0.75f, 0.25f));
            TL += new Vector3(newW, 0, 0);
            CreateQuad(TL, cornerW, cornerW, new Vector2(0.75f, 0), new Vector2(1.0f, 0.25f));

            // Main bit along the middle
            TL = new Vector3(-w / 2, h / 2, 0.0f);
            TL += new Vector3(0, -cornerW, 0);
            CreateQuad(TL, cornerW, newh, new Vector2(0, 0.25f), new Vector2(0.25f, 0.75f));
            TL += new Vector3(cornerW, 0, 0);
            //CreateQuad(TL, newW, newh, new Vector2(0.25f, 0.25f), new Vector2(0.75f, 0.75f));
            TL += new Vector3(newW, 0, 0);
            CreateQuad(TL, cornerW, newh, new Vector2(0.75f, 0.25f), new Vector2(1.0f, 0.75f));


            TL = new Vector3(-w / 2, h / 2, 0.0f);
            TL += new Vector3(0, -cornerW - newh, 0);
            CreateQuad(TL, cornerW, cornerW, new Vector2(0, 0.75f), new Vector2(0.25f, 1.0f));
            TL += new Vector3(cornerW, 0, 0);
            CreateQuad(TL, newW, cornerW, new Vector2(0.25f, 0.75f), new Vector2(0.5f, 1.0f));
            TL += new Vector3(newW, 0, 0);
            CreateQuad(TL, cornerW, cornerW, new Vector2(0.75f, 0.75f), new Vector2(1.0f, 1.0f));
        }
    }
}
